package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author XinxuanZhuo
 * @since 2024-02-27
 */

@Api(tags = "互动提问的问题相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;


    /**
     * 新增提问
     */
    @ApiOperation("用户新增提问(问题)")
    @PostMapping
    public void saveQuestion(@RequestBody @Validated QuestionFormDTO questionFormDTO) {
        questionService.saveQuestion(questionFormDTO);
    }

    /**
     * 修改提问
     */
    @ApiOperation("用户修改提问(问题)")
    @PutMapping("/{id}")
    public void editQuestion(@PathVariable Long id, @RequestBody QuestionFormDTO questionFormDTO) {
        questionService.editQuestion(id, questionFormDTO);
    }

    /**
     * 用户端分页查询问题列表
     */
    @ApiOperation("用户端分页查询问题列表")
    @GetMapping("/page")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery pageQuery) {
        return questionService.queryQuestionPage(pageQuery);
    }

    /**
     * 根据问题id查询问题详情
     */
    @ApiOperation("根据问题id查询问题详情")
    @GetMapping("/{id}")
    public QuestionVO queryQuestionById(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        return questionService.queryQuestionById(id);
    }

    /**
     * 根据问题id删除问题
     */
    @ApiOperation("根据问题id删除问题")
    @DeleteMapping("/{id}")
    public void deleteQuestionById(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        questionService.deleteQuestionById(id);
    }


}
